package cate.game.play.buff.h;

import cate.game.attr.FightAttr;
import cate.game.play.buff.BuffHandler;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;

/**
 * 增加15%攻击力，且场上每存在1名已死亡的队友，增加10%攻击力，持续3回合
 */
public class 追忆BH extends BuffHandler {

	private FightAttr 属性提升;

	//属性提升=4:1000
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		属性提升 = new FightAttr(args.get("属性提升"));
	}

	private int recordNum;

	@Override
	public void onAdd(ActionCtx action) {
		settle();
	}

	@Override
	public void onMoveDone(MoveCtx move, TimeActionCtx action) {
		settle();
	}

	private void settle() {
		int deadNum = buff.owner.getFightTeam().getFightersDead().size();
		if (deadNum == recordNum) {
			return;
		}
		buff.owner.attr.addAttr(属性提升.copy().scale(deadNum - recordNum));
		recordNum = deadNum;
	}

	@Override
	public void onInvalid(ActionCtx action, byte invalidReason) {
		buff.owner.attr.addAttr(属性提升.copy().scale(-recordNum));
	}
}
